﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SNSpirit.Domain
{
    /// <summary>
    /// Domain Entity with status support
    /// </summary>
    public class StatusDomainEntity : DomainEntity
    {
        public void EnterBusy()
        {
            Interlocked.Increment(ref this._waitCount);
        }

        public void ExitBusy()
        {
            Interlocked.Decrement(ref this._waitCount);
        }

        public bool IsBusy
        {
            get
            {
                return this._waitCount != 0;
            }
        }

        protected virtual void OnErrorOccurred(Exception error, string desp)
        {
            // to do
        }

        public event EventHandler ErrorOccurred;

        #region private

        private int _waitCount = 0;

        #endregion private
    }
}